home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_200 / 285_02 / gram.h < prev    next >
C/C++ Source or Header  |  1990-07-08  |  5KB  |  122 lines

  1. /*
  2. **    file:        gram.h
  3. **    purpose:    Grammar variables header definitions
  4. **    author:        DrH 1/4/88 [bison]
  5. */
  6. /* Data definitions for internal representation of bison's input,
  7.    Copyright (C) 1984, 1986 Bob Corbett and Free Software Foundation, Inc.
  8.  
  9. BISON is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY.  No author or distributor accepts responsibility to anyone
  11. for the consequences of using it or for whether it serves any
  12. particular purpose or works at all, unless he says so in writing.
  13. Refer to the BISON General Public License for full details.
  14.  
  15. Everyone is granted permission to copy, modify and redistribute BISON,
  16. but only under the conditions described in the BISON General Public
  17. License.  A copy of this license is supposed to have been given to you
  18. along with BISON so you can know your rights and responsibilities.  It
  19. should be in a file named COPYING.  Among other things, the copyright
  20. notice and this notice must be preserved on all copies.
  21.  
  22.  In other words, you are welcome to use, share and improve this program.
  23.  You are forbidden to forbid anyone else to use, share and improve
  24.  what you give them.   Help stamp out software-hoarding!
  25. */
  26.  
  27. /* representation of the grammar rules:
  28.  
  29. ntokens is the number of tokens, and nvars is the number of
  30. variables (nonterminals). nsyms is the total number, ntokens + nvars.
  31.  
  32. Each symbol (either token or variable) receives a symbol number.
  33. Numbers 0 to ntokens-1 are for tokens, and ntokens to nsyms-1 are
  34. for variables. Symbol number zero is the end-of-input token.
  35. This token is counted in ntokens.
  36.  
  37. The rules receive rule numbers 1 to nrules in the order they are written.
  38. Actions and guards are accessed via the rule number.
  39.  
  40. The rules themselves are described by three arrays: rrhs, rlhs and ritems.
  41. rlhs[r] is the symbol number of the left hand side of rule r.
  42. The right hand side is stored as symbol numbers in a portion of ritems.
  43. rrhs[r] contains the index in ritems of the beginning of
  44.  the portion for rule r.
  45. The length of the portion is one greater
  46.  than the number of symbols in the rule's right hand side.
  47. The last element in the portion contains minus r, which
  48. identifies it as the end of a portion and says which rule it is for.
  49.  
  50. The portions of ritems come in order of increasing rule number and are
  51. followed by an element which is zero to mark the end.  nitems is the
  52. total length of ritems, not counting the final zero.  Each element of
  53. ritems is called an "item" and its index in ritems is an item number.
  54.  
  55. Item numbers are used in the finite state machine to represent
  56. places that parsing can get to.
  57.  
  58. Precedence levels are recorded in the vectors sprec and rprec.
  59. sprec records the precedence level of each symbol,
  60. rprec the precedence level of each rule.
  61.  
  62. Precedence levels are assigned in increasing order starting with 1
  63. so that numerically higher precedence values mean tighter binding
  64. as they ought to.  Zero as a symbol or rule's precedence
  65.  means none is assigned.
  66.  
  67. Associativities are recorded similarly in rassoc and sassoc.
  68. */
  69.  
  70.  
  71. #define ISTOKEN(s)  ((s) < ntokens)
  72. #define ISVAR(s)    ((s) >= ntokens)
  73.  
  74.  
  75. extern int nitems;
  76. extern int nrules;
  77. extern int nsyms;
  78. extern int ntokens;
  79. extern int nvars;
  80.  
  81. extern short *ritem;
  82. extern short *rlhs;
  83. extern short *rrhs;
  84. extern short *rprec;
  85. extern short *sprec;
  86. extern short *rassoc;
  87. extern short *sassoc;
  88. extern short *rline;        /* Source line number of each rule */
  89.  
  90. extern int start_symbol;
  91.  
  92.  
  93. /* associativity values in elements of rassoc, sassoc.  */
  94.  
  95. #define RIGHT_ASSOC 1
  96. #define LEFT_ASSOC 2
  97. #define NON_ASSOC 3
  98.  
  99. /* token translation table:
  100. indexed by a token number as returned by the user's yylex routine,
  101. it yields the internal token number used by the parser and throughout bison.
  102. If translations is zero, the translation table is not used because
  103. the two kinds of token numbers are the same.  */
  104.  
  105. extern short *token_translations;
  106. extern int translations;
  107. extern int max_user_token_number;
  108.  
  109. /* semantic_parser is nonzero if the input file says to use the hairy parser
  110. that provides for semantic error recovery.  If it is zero, the yacc-compatible
  111. simplified parser is used.  */
  112.  
  113. extern int semantic_parser;
  114.  
  115. /* pure_parser is nonzero if should generate a parser that is all pure and reentrant. */
  116.  
  117. extern int pure_parser;
  118.  
  119. /* error_token_number is the token number of the error token.  */
  120.  
  121. extern int error_token_number;
  122.